<?php

declare(strict_types=1);

namespace App\Entities;

class AreaEntity extends ABaseEntity
{
    public function __construct(AreaModel $model)
    {
        $this->model = $model;
    }

    /**
     * @return int
     */
    public static function getCityIdByAreaName(string $areaName)
    {
        $model = AreaModel::where('areaname', $areaName)->first();
        if ($model === null) {
            return 0;
        }

        return $model->id;
    }

    public static function getOpenRootCityList()
    {
        return AreaModel::where(['is_open' => 1, 'level' => 1])->select(['id', 'areaname'])->get();
    }

    /**
     * @return int
     */
    public function getId()
    {
        return $this->model->id;
    }

    public function getAreaname(): string
    {
        return (string) $this->model->areaname;
    }

    public function getArealevel(): int
    {
        return (int) $this->model->level;
    }

    public function getAreaparentid(): int
    {
        return (int) $this->model->parentid;
    }

    public function getAreaisopen(): int
    {
        return (int) $this->model->is_open;
    }
}
